<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/header.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
   <script>
var xmlhttp;
var result;
function validateName(){
	var username=document.getElementById("username").value;
	var url="${ctx}/UserManageServlet?function=validateName&username="+username;
	//ie5,ie6
	if(window.ActiveXObject){
    	xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    }else {
    	//ie7,ie8,firefox
       xmlhttp= new XMLHttpRequest();
    }
	xmlhttp.onreadystatechange= trigered;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function trigered(){
  if(xmlhttp.readyState==4&&xmlhttp.status==200){
	result=xmlhttp.responseText;	
	if(result=="false"){
		document.getElementById("output").innerHTML="<div style='color:red'>用户名已经被使用</div>";
	}else{
		document.getElementById("output").innerHTML="<div style='color:red'>用户名可以使用</div>";
	}
  }
}

</script>

</head>
  
  <body>
     <form action="${ctx}/user/add" method="post" onsubmit="return validate(this)">
	用户名：<input name="username" type="text" onblur="validateName()"/> <br> 
	     <span id="output"></span>

	密码：<input name="password" type="password"/><br> 
	<input type="submit" name="optype" value="注册"/>
     </form>
  </body>

</html>
	<script type="text/javascript">
		function validate(myform){
		 	if(result=="false"){
	     		alert("用户名已存在！");
				myform.username.focus();
	     		return false;
		 	}
		 	if(myform.username.value.length == 0){
	     		alert("用户名不能为空！");
				myform.username.focus();
	     		return false;
		 	}
		 	if(myform.password.value.length < 4){
	     		alert("密码长度不能小于4！");
				myform.password.focus();
	     		return false;
		 	}
			return true;
		}
	</script>
<%@ include file="/footer.htm"%>